package com.qf.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.qf.ssm.common.exception.ServiceException;
import com.qf.ssm.common.request.OrderAppRequestParams;
import com.qf.ssm.common.request.OrderRequestParams;
import com.qf.ssm.common.vo.ResponseCode;
import com.qf.ssm.entity.Order;
import com.qf.ssm.mapper.OrderAppMapper;
import com.qf.ssm.service.OrderAppService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ISALYL
 * @create 2021-10-12 16:27
 */
@Service
public class OrderAppServiceImpl implements OrderAppService {
    @Resource
    private OrderAppMapper orderAppMapper;


    @Override
    public List<Order> listOrder(Long memberId, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<Order> orders = orderAppMapper.selectOrder(memberId);
        return orders;
    }

    @Override
    public List<Order> findOrderByName(Long memberId, Long orderName, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<Order> orders = orderAppMapper.selectOrderByName(memberId,orderName);
        return orders;
    }

    @Override
    public Integer modOrder(OrderRequestParams params) {
        Order order = new Order();
        BeanUtils.copyProperties(params,order);
        Integer i = orderAppMapper.updateOrderName(order);
        if (i >0){
            return i;
        }else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public Integer cancelOrder(OrderRequestParams params) {
        Order order = new Order();
        BeanUtils.copyProperties(params,order);
        Integer i = orderAppMapper.cancelOrderName(order);
        if (i >0){
            return i;
        }else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public Integer payOrder(OrderRequestParams params) {
        Order order = new Order();
        BeanUtils.copyProperties(params,order);
        Integer i = orderAppMapper.payOrderName(order);
        if (i >0){
            return i;
        }else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public Integer sendOrder(OrderRequestParams params) {
        Order order = new Order();
        BeanUtils.copyProperties(params,order);
        Integer i = orderAppMapper.sendOrderName(order);
        if (i >0){
            return i;
        }else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public Integer receiveOrder(OrderRequestParams params) {
        Order order = new Order();
        BeanUtils.copyProperties(params,order);
        Integer i = orderAppMapper.receiveOrderName(order);
        if (i >0){
            return i;
        }else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public Integer completeOrder(OrderRequestParams params) {
        Order order = new Order();
        BeanUtils.copyProperties(params,order);
        Integer i = orderAppMapper.completeOrderName(order);
        if (i >0){
            return i;
        }else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public Integer statusOrder(OrderRequestParams params) {
        Order order = new Order();
        BeanUtils.copyProperties(params,order);
        Integer i = orderAppMapper.statusOrderName(order);
        if (i >0){
            return i;
        }else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public Boolean deleteOrder(Long orderId) {
        Integer delete = orderAppMapper.delOrder(orderId);
        if (delete > 0){
            return true;
        }else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }
}
